package com.chixing.day03.day03_Test;

/**
 * 1.声明并初始化二维数组
 * 2.给数组的元素赋值
 * 2.1 给首末元素赋值
 * 2.2 给每行的非首末元素赋值
 * 3.遍历二维数组
 */
public class YangHuiTriangle {
    public static void main(String[] args) {
        int[][] arr = new int[8][];
        for (int i = 0; i < arr.length; i++) {
            arr[i] = new int[i + 1]; //行
            arr[i][0] = arr[i][i] = 1;
            for (int j = 1; j < arr[i].length - 1; j++) { //列
                arr[i][j] = arr[i - 1][j - 1] + arr[i - 1][j];  //每一元素是它上一个元素斜对角之和
            }
        }
        for (int i = 0; i < arr.length; i++) {
            for (int j = 0; j < arr[i].length; j++) {
                System.out.print(arr[i][j] + " ");
            }
            System.out.println();
        }

    }
}

